package batch.common.db;

import java.sql.*;
import java.util.*;
import java.io.*;
import batch.common.secui.*;

public class ConnectionManager {
    private static String sURL;
    private static String sUser;
    private static String sPass;
    private static Properties props = null;
    static {
        try {
            props = new Properties();
            props.load(new FileInputStream("/home01/sfc/batch/common/db.properties"));
            
            TripleDES des = new TripleDES("QWERTYUIOP!@#$%^&*()aaaa");

            sURL = des.decrypt((String)props.get("url"));
            sUser = des.decrypt((String)props.get("user"));
            sPass = des.decrypt((String)props.get("password"));
            props.setProperty("user",sUser);
            props.setProperty("password",sPass);

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static Connection getConnection() {
        Connection conn = null;
        try{
        	
        	Driver myDriver = (Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();        	
            conn = myDriver.connect(sURL,props);   
            conn.setAutoCommit(false);
            
		} catch (InstantiationException instantiationexception) {
			instantiationexception.printStackTrace();
		} catch (IllegalAccessException illegalaccessexception) {
			illegalaccessexception.printStackTrace();
		} catch (ClassNotFoundException classnotfoundexception) {
			classnotfoundexception.printStackTrace();
		} catch (SQLException sqlexception) {
			sqlexception.printStackTrace();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
        return conn;
    }
}
